//
//  YTSelecteCarTypeViewModel.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/7/8.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTSelecteCarTypeViewModel.h"
#import "YTDriverCarServices.h"
#import "YTCarBandTypeModel.h"

@interface YTSelecteCarTypeViewModel ()
@property (strong, nonatomic, readwrite) RACSignal *loadBandList;
@end

@implementation YTSelecteCarTypeViewModel

- (void)initialize {
    [super initialize];
    [self loadBandAndColorData];
}

#pragma mark - 加载品牌和颜色数据

- (void)loadBandAndColorData {
    _bandArray = [NSArray array];
    _colorArray = [NSArray array];
    _versionArray = [NSArray array];
    @weakify(self);
    _loadBandList = [[YTDriverCarServices getCarBandAndColor] map:^id(NSDictionary *response) {
        @strongify(self);
        NSDictionary *dict = response[@"responseData"];
        NSMutableArray<YTCarBandTypeModel *> *temp = [NSMutableArray array];
        temp = [[NSArray yy_modelArrayWithClass:[YTCarBandTypeModel class] json:dict[@"brandList"]] mutableCopy];
        for (YTCarBandTypeModel *model in [temp copy]) { /// 这里要滤掉很多没
            if (!model.versionList.count) {
                [temp removeObject:model];
            }
        }
        self.bandArray = temp;
        return self.bandArray;
    }];
    
    [[YTDriverCarServices getCarColor] subscribeNext:^(NSDictionary *response) {
        NSDictionary *dict = response[@"responseData"];
        self.colorArray = [NSArray yy_modelArrayWithClass:[YTBandColorModel class] json:dict[@"colorList"]];
    }];
}

@end
